/*
 * Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.security.authentication;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

/**
 * 认证相关的核心接口，也是发起认证的出发点
 */
public interface AuthenticationManager {

	/**
	 * 对 {@link Authentication} 对象进行身份验证， 认证成功后返回新的 Authentication 对象（用户信息、权限信息）。
	 *
	 * AuthenticationManager 必须遵循以下有关的规定
	 *     1. 如果禁用了账户，必须抛出 {@link DisabledException} 异常
	 *     2. 如果账户被锁定，必须抛出 {@link LockedException} 异常
	 *     3. 如果用户名密码不正确，必须抛出 {@link BadCredentialsException} 异常
	 *
	 * 异常按上面的顺序进行抛出
	 * 如果帐户被禁用或锁定，则身份验证请求将立即被拒绝并且不执行凭据测试过程，防止针对禁用或锁定的帐户测试凭据。
	 *
	 * @param authentication 对象
	 * @return 完全认证的对象，包括凭据
	 * @throws AuthenticationException 认证失败异常
	 */
	Authentication authenticate(Authentication authentication) throws AuthenticationException;

}
